from flask import Blueprint, render_template, request, abort, flash
from app.models import Article
from app.constants import PAGE_LIMIT

home_controller = Blueprint("home", __name__)

@home_controller.route("/")
def index():
    page = request.args.get('page', 1, type=int)
    try:
        pagination = Article.query.order_by(Article.id.desc()).paginate(page = page, per_page=PAGE_LIMIT)
    except Exception as e:
        flash(str(e))
        abort(500)
    return render_template('home/index.html', pagination=pagination)